import { GetUserInfoApi } from '@/request/user/user-api'

export default {
  namespaced: true,
  state: {
    //用户信息，还需要再被本地存储一份
    userInfo:JSON.parse(localStorage.getItem("expert-userInfo"))||{
      id: null,
      account: null,
      name: '默认',
      role: null
    }
  },
  mutations: {
    changeUserInfo (state, payload) {
      state.userInfo = payload
      localStorage.setItem("expert-userInfo",JSON.stringify(state.userInfo))
    }
  },
  actions: {
    async asyncChangeUserInfo ({ commit }, payload) {
      let res = await GetUserInfoApi(payload)
      if (!res) return
      commit('changeUserInfo', {
        id: res.data.id,
        account: res.data.account,
        name: res.data.name,
        role: res.data.role
      })
    }
  }
}
